package cn.reinforce.util.dsm;

import cn.reinforce.util.dsm.model.ApiInfo;
import cn.reinforce.util.dsm.model.LoginData;
import cn.reinforce.util.dsm.model.Result;
import cn.reinforce.util.http.HttpClientUtil;
import cn.reinforce.util.http.model.HttpResult;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 幻幻Fate
 * @date 2021/10/19
 */
public enum Dsm {
    INSTANCE;

    private String domain;

    private String port;

    private String username;

    private String password;

    private String sid;

    private boolean ssl;

    /**
     * DSM系统版本
     */
    private Integer version;

    private String baseUrl;

    private Map<String, ApiInfo> apis = new HashMap<>();

    public void init(String domain, String port, String username, String password, boolean ssl, Integer version) {
        this.domain = domain;
        this.port = port;
        this.username = username;
        this.password = password;
        this.ssl = ssl;
        this.version = version;
        this.baseUrl = (ssl ? "https://" : "http://") + domain + ":" + port + "/webapi/";

        this.sid = AuthUtil.login();
        this.apis = AuthUtil.getApiList();
    }

    public String getUsername() {
        return username;
    }

    public String getPassword() {
        return password;
    }

    public String getSid() {
        return sid;
    }

    public boolean isSsl() {
        return ssl;
    }

    public Integer getVersion() {
        return version;
    }

    public String getBaseUrl() {
        return baseUrl;
    }

    public Map<String, ApiInfo> getApis() {
        return apis;
    }

    @Override
    public String toString() {
        return "Dsm{" +
                "domain='" + domain + '\'' +
                ", port='" + port + '\'' +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", sid='" + sid + '\'' +
                ", ssl=" + ssl +
                ", version=" + version +
                ", baseUrl='" + baseUrl + '\'' +
                '}';
    }
}
